package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.DBmake.PostgreDB;
import com.example.demo.JsonObj.FriListObj;
import com.example.demo.Utils.JsonUtil;
import com.example.demo.Utils.TokenUtil;
import com.example.demo.api.CommonResult;
import com.example.demo.entity.HeartbeatInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
public class InitController {
    @RequestMapping(value = "/init",method = RequestMethod.POST)
    public CommonResult login(@RequestBody HeartbeatInfo heartbeatInfo){

        String token = heartbeatInfo.getToken();
        if(token==null)  return CommonResult.unauthorized("登录过期");
        if(!TokenUtil.verify(token)) return CommonResult.unauthorized("登录过期");

        int Uid = heartbeatInfo.getUid();
        PostgreDB Target = new PostgreDB();

        String Img = Target.GetHeadPic(Uid);
        String nickname = Target.GetNickname(Uid);
        return CommonResult.success(Img,nickname);
    }
}